package com.fr.chicken.manager.configure;

import com.fr.chicken.dao.MaxConfigureDao;
import com.fr.chicken.model.MaxConfigure;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.validation.constraints.Max;

@Repository
public class ConfigManager {

    @Autowired
    private MaxConfigureDao maxConfigureDao;

//    public <T> T getConfig(EConfigure configId,Class<T> resultType){
//        MaxConfigure mc = maxConfigureDao.selectByPrimaryKey(configId.getValue());
//        if(mc == null){
//            resultType.getClass().newInstance()
//
//        }
//    }

    public int getIntConfig(EConfigure configType){
        MaxConfigure mc = maxConfigureDao.selectByPrimaryKey(configType.getValue());
        if(mc == null){
            return 0;
        }
        try{
           return Integer.parseInt( mc.getValue());
        }catch (NumberFormatException e){
            return 0;
        }
    }
    public int getIntConfig(int configId){
        MaxConfigure mc = maxConfigureDao.selectByPrimaryKey(configId);
        if(mc == null){
            return 0;
        }
        try{
            return Integer.parseInt( mc.getValue());
        }catch (NumberFormatException e){
            return 0;
        }
    }
}
